package com.markerhub.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.markerhub.common.ResponseJson;
import com.markerhub.entity.Blog;
import com.markerhub.entity.Link;
import com.markerhub.service.BlogService;
import com.markerhub.service.LinkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 关注公众号：MarkerHub
 * @since 2021-04-10
 */
@Api(value = "LinkController",tags = "博客链接接口")
@RestController
@RequestMapping("/link")
public class LinkController {
    @Autowired
    LinkService linkService;

    @ApiOperation(value = "获取友链信息")
    @GetMapping("/LinkList")
    public Object getLinkList(){
        List<Link> links=linkService.getLinkList();
        try{
            return ResponseJson.success(links);
        }catch (Exception e)
        {
            return ResponseJson.failure(e.getMessage());
        }
    }

    @ApiOperation(value = "增加友链")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "linkName",value = "链接名称",required = true,dataType = "string"),
            @ApiImplicitParam(name = "avatarLink",value = "图片链接",required = true,dataType = "string"),
            @ApiImplicitParam(name = "blogLink",value = "博客链接",required = true,dataType = "string"),
            @ApiImplicitParam(name = "description",value = "描述",required = true,dataType = "string"),
    })
    @PostMapping("/addLink")
    public Object addLink(String linkName,String avatarLink,String blogLink,String description){
        try{
            linkService.addLink(linkName,avatarLink,blogLink,description);
            return ResponseJson.success();
        }catch (Exception e)
        {
            return ResponseJson.failure(e.getMessage());
        }
    }
}
